< previous page page_554 next page >

Page 554
0554-01.jpg
Figure 14.12.
A sample Microsoft data control error message.
Let's modify the program a bit to show you how you can use the Data1_Error event. First, add a CommonDialog control to your form. Then edit the DatabaseName property of the data control to read C:\ERRORDB.MDB. Next, add the code from Listing 14.11 to the Data1_Error event.
Type.gifListing 14.11. Coding the Data1_Error event.
Private Sub Data1_Error(DataErr As Integer, Response As Integer)
    '
    ' add error-trapping for data errors
    '
    Dim strFileName As String
    '
    Select Case DataErr
        Case 3044 ' database not found
            MsgBox "Unable to locate data file", vbExclamation, "Database
arrow.gifMissing"
            '
            CommonDialog1.DialogTitle = "Locate ERRORDB.MDB"
            CommonDialog1.filename = "ERRORDB.MDB"
            CommonDialog1.Filter = "*.mdb"
            CommonDialog1.ShowOpen
            Data1.DatabaseName = CommonDialog1.filename
            '
            Response = vbCancel ' cancel auto-message
    End Select
    '
End Sub
Notice that the code in Listing 14.11 checks to see whether the error code is 3044. This is the error number that corresponds to the "database missing" message. If the 3044 code is reported, the user sees a short message and then the file open dialog, ready to locate and load the database. Finally, notice the line that sets the Response parameter to vbCancel. This step tells Visual Basic not to display the default message.

 
< previous page page_554 next page >

If you like this book, buy it!